package com.cao.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cao.common.utils.SecurityUtils;
import com.cao.project.domain.Task;
import com.cao.project.domain.TaskComment;
import com.cao.project.mapper.TaskMapper;
import com.cao.project.service.ITaskCommentService;
import com.cao.project.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 任务：存储项目下的任务信息Service业务层处理
 *
 * @author cao
 * @date 2025-03-03
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {
    @Autowired
    private ITaskCommentService commentService;

    /**
     * 查询任务：存储项目下的任务信息列表
     *
     * @param task 任务：存储项目下的任务信息
     * @return 任务：存储项目下的任务信息
     */
    @Override
    public List<Task> selectTaskList(Task task) {
        return baseMapper.selectTaskList(task);
    }

    @Override
    public List<Task> getMyTask(Task task) {
        task.setAssignedTo(SecurityUtils.getUserId());
        return baseMapper.selectTaskList(task);
    }

    @Override
    @Transactional
    public int del(List<Long> list) {
        commentService.remove(new LambdaQueryWrapper<TaskComment>().in(TaskComment::getTaskId, list));
        return baseMapper.deleteBatchIds(list);
    }
}
